package com.yonyou.pmclouds.discuss.impl;

import com.yonyou.pmclouds.discuss.itf.SpecifiedTypeDiscussProcessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DiscussConfiguration implements BeanPostProcessor {
    private DiscussProcessor processor = new DiscussProcessor();

    @Bean
    public DiscussProcessor discussProcessor() {
        return processor;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof SpecifiedTypeDiscussProcessor) {
            processor.addProcessor((SpecifiedTypeDiscussProcessor) bean);
        }
        return bean;
    }
}
